////////////////////////////////////////////////////////////////////////////////
//
//  FLYING KIWI BV
//  Copyright 2010 Flying Kiwi BV
//  All Rights Reserved.
//
//  NOTICE: Flying Kiwi permits you to use, modify, and distribute this file
//  in accordance with the terms of the license agreement accompanying it.
//
////////////////////////////////////////////////////////////////////////////////
package plantool.helpers {
	//--------------------------------------------------------------------------
	//  Imports
	//--------------------------------------------------------------------------
	//--------------------------------------------------------------------------
	//  [Metadata (Events, Style, Effects etc)]
	//--------------------------------------------------------------------------
	
	//--------------------------------------------------------------------------
	//  Class declaration
	//--------------------------------------------------------------------------
	public class ClassHelper {
		//--------------------------------------------------------------------------
		//Class constants
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//Class variables
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//Class properties
		//--------------------------------------------------------------------------
		
		//--------------------------------------------------------------------------
		//Constructor and Destructor
		//--------------------------------------------------------------------------
		public function ClassHelper()
		{
		}
		
		//--------------------------------------------------------------------------
		//Class methods
		//--------------------------------------------------------------------------
		public static function validateClass(cls:Class, iface:Class):Boolean {
			var result:Boolean = false;
			try {
				//try to create an instance of object as iUserRow
				var obj:* = new cls();
				//validate object against interface
				if (obj is iface) {
					result = true;
				}
				
				//try to dispose the object
				try {
					if (obj.hasOwnProperty("dispose") && obj["dispose"] is Function) {
						obj["dispose"]();
					}
				} catch (e:Error) {
					trace("WARNING!! - Dispose of class failed during ClassHelper.validateClass", cls, " as class", iface);
					trace(" -", e.message)
				}
			} catch (e:Error) {
				//we caught an error, inform user!
				trace("Error creating ", iface, " from class", cls);
				trace(" -", e.message);
			}
			
			return result;
		}
	}
}